package com.dwy2002.course.config;


import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import static com.dwy2002.enums.rabbit.CourseRabbitConstants.*;
import static com.dwy2002.enums.rabbit.DlxRabbitConstants.DLX_EXCHANGE;
import static com.dwy2002.enums.rabbit.DlxRabbitConstants.DLX_ROUTING_KEY;

/**
 * 课程rabbit配置类
 *
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/03/22
 */
@Configuration
public class CourseRequestRabbitConfig {
    // 队列声明
    @Bean
    public Queue enrollmentRequestQueue() {
        return QueueBuilder.durable(ENROLLMENT_REQUEST_QUEUE)
                .deadLetterExchange(DLX_EXCHANGE) // 绑定死信交换机
                .deadLetterRoutingKey(DLX_ROUTING_KEY)
                .build();
    }

    // 交换机声明
    @Bean
    public DirectExchange enrollmentRequestExchange() {
        return new DirectExchange(ENROLLMENT_REQUEST_EXCHANGE);
    }

    // 绑定声明
    @Bean
    public Binding enrollmentRequestBinding() {
        return BindingBuilder.bind(enrollmentRequestQueue())
                .to(enrollmentRequestExchange())
                .with(ENROLLMENT_REQUEST_ROUTING_KEY);
    }
}
